package com.htht.smartschool.action.school;

import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.tschool.TSchool;
import com.htht.smartschool.service.tschool.SchoolService;
import com.htht.smartschool.util.system.GsonUtils;

public class SchoolAction extends BaseAction{

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		 
		boolean flag = false;
		SchoolService shoolService = new SchoolService();
		TSchool tshool = (TSchool) GsonUtils.getInstance().fromJson(pd.getData(), TSchool.class);
		if(pd.getCmd().equalsIgnoreCase("getSchoolByPage")){
			@SuppressWarnings("rawtypes")
			Map map = shoolService.getSchoolByPage(tshool);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("获取学校信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addSchoolInfo")){
			//add
			TSchool shool = shoolService.addSchoolInfo(tshool);
			if(shool != null){
				flag = true;
				obj.setData(shool);
			}else{
				obj.setData("新增学校信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateSchoolInfo")){
			//update
			boolean shool = shoolService.updateTSchoolInfo(tshool);
			if(shool == true){
				flag = true;
				obj.setData(shool);
			}else{
				obj.setData("更新学校信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteSchoolInfo")){
			//delete
			boolean shool = shoolService.deleteTSchoolInfo(tshool);
			if(shool == true){
				flag = true;
				obj.setData(shool);
			}else{
				obj.setData("删除学校信息失败");
			}
		}
		return flag;
	}

}
